﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.MenuCommand;
using B.S.BaseData.Read.API.DTO;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.MenuHandler
{
    public class MenuSelectHandler : IRequestHandler<MenuSelectCommand, APIResult<List<MenuManagement>>>
    {
        private readonly IBaseRepository<MenuManagement> _menuRepository;

        public MenuSelectHandler(IBaseRepository<MenuManagement> menuRepository)
        {
            _menuRepository = menuRepository;
        }

        public async Task<APIResult<List<MenuManagement>>> Handle(MenuSelectCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MenuManagement>> result = new APIResult<List<MenuManagement>>();
            result.Code = APIEnum.Success;
            result.Msg = APIEnum.Success.ToString();


            var list = _menuRepository.GetAll().ToList();
            result.Data = list;

            return await Task.FromResult(result);
        }
    }
}
